#!/bin/bash

ARTIFACTID="$1"
#REGISTRY_SVR="172.26.224.116:5000"
REGISTRY_SVR=$DOCKER_REGISTRY_SVR

HARBOR_REGISTRY_SVR=""

if [[ -z $REGISTRY_SVR ]]; then
  REGISTRY_SVR="192.168.0.39:5000"
  HARBOR_REGISTRY_SVR="harbor.k8s.local"
fi

#VERSION=`mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.version -q -DforceStdout`
VERSION=`cat $2/version`

APPID="$ARTIFACTID:v$VERSION"
echo "APPID=$APPID"

docker login $REGISTRY_SVR --username=admin --password=admin
docker build -t $APPID .
docker tag $APPID $REGISTRY_SVR/$APPID
docker push $REGISTRY_SVR/$APPID
docker logout $REGISTRY_SVR


if [[ -n $HARBOR_REGISTRY_SVR ]]; then
  docker login $HARBOR_REGISTRY_SVR --username=admin --password=Harbor12345
  docker tag $APPID $HARBOR_REGISTRY_SVR/ruoyi/$APPID
  docker push $HARBOR_REGISTRY_SVR/ruoyi/$APPID
  docker logout $HARBOR_REGISTRY_SVR
fi
